public class Demo2 {
    private static Object lock1=new Object();
    private static Object lock2=new Object();
    public static void main(String[] args) {
        Thread t1=new Thread(()->{
            synchronized (lock1){
                System.out.println("线程t1对lock1加锁成功");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            synchronized (lock2){
                System.out.println("线程t1对lock2加锁成功");
            }
        });
        Thread t2=new Thread(()->{
            synchronized (lock1){
                System.out.println("线程t2对lock2加锁成功");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            synchronized (lock2){
                System.out.println("线程t2对lock1加锁成功");
            }
        });
        Thread t3=new Thread(()->{
            synchronized (lock1){
                System.out.println("线程t3对lock1加锁成功");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            synchronized (lock2){
                System.out.println("线程t3对lock2加锁成功");
            }
        });
        t1.start();
        t2.start();
        t3.start();
    }
}
